﻿using System;
using System.Collections.Generic;
using System.Linq;
using KZ.Lottery.DAL;
using KZ.Lottery.Entities;
using KZ.Lottery.Resources;
using KZ.Utilities;

namespace KZ.Lottery.BLL
{
    public class SettingBLL
    {
        public static List<Setting> GetSettingList(string settingID)
        {
            return SettingDAL.GetSettingList(settingID);
        }

        public static Setting GetSetting(string settingID)
        {
            return SettingDAL.GetSetting(settingID);
        }

        public static bool CheckSetting()
        {
            List<Setting> settingList = GetSettingList(String.Empty);
            if (String.IsNullOrEmpty(settingList.Single(s => s.SettingID == KZ_Resource.Setting_CapitalRate).SettingValue))
            {
                return false;
            }
            if (String.IsNullOrEmpty(settingList.Single(s => s.SettingID == KZ_Resource.Setting_WinRate).SettingValue))
            {
                return false;
            }

            Global.WinRate = Utility.DecimalParse(SettingDAL.GetSetting(KZ_Resource.Setting_WinRate).SettingValue);
            Global.CapitalRate = Utility.DecimalParse(SettingDAL.GetSetting(KZ_Resource.Setting_CapitalRate).SettingValue);
            Global.Rate = Utility.DecimalParse(SettingDAL.GetSetting(KZ_Resource.Setting_Rate).SettingValue);
            Global.GroupDay = Utility.IntParse(SettingDAL.GetSetting(KZ_Resource.Setting_GroupDay).SettingValue);
            Global.Loop = Utility.IntParse(SettingDAL.GetSetting(KZ_Resource.Setting_Loop).SettingValue);

            return true;
        }

        public static bool CheckConnection()
        {
            return SettingDAL.CheckConnection();
        }

        public static bool UpdateSetting(List<Setting> settingList)
        {
            return SettingDAL.UpdateSetting(settingList);
        }
    }
}